#
# tcl script for MeanDark
#

set w .meandark
catch {destroy $w}

toplevel $w

wm title $w "MeanDark"
wm iconname $w "dark"
positionWindow $w

set tfont "Helvetica 18 bold"

label $w.title -font $tfont -text " MeanDark\n "
pack $w.title -side top

#frame $w.msg
#pack $w.msg

#label $w.msg.t
#pack $w.msg.t -side top

label $w.t1 -font $font -wraplength 4i -text "Utility for the dark frame subtract.\n"
pack $w.t1
 
#label $w.t2 -font $font -wraplength 4i -text "Follow next entries and read instruction to get photometry of your data set: \n" 
#pack $w.t2

#label $w.t3 -font $font -wraplength 4i -text "Read carefully these instruction.\n"
#pack $w.t3

#Please give mask for input images."

proc filelist {arg list} {

$list delete 0 end
foreach i [glob [$arg get]] {
  $list insert end $i
}
}

proc ilist {list} { 

set f [open "ls.dir" "w"]

puts $f {$list}

#for {set i 0} {$i < [$list size]} {incr i} {
#    if {[$list selection includes $i ] == 1}  {
#    puts $f [$list get $i]
#  }
}
close $f
}

proc konvert {list} {

ilist $list
eval exec "cat ls.dir"
#eval exec "/home/f/munipack/konve/konve"
}

frame $w.left
frame $w.right
pack $w.left $w.right -side left

#frame $w.buttons  
#pack $w.buttons -side bottom -fill x -pady 2m 
#button $w.buttons.ok -text OK -command "destroy $w"
#button $w.buttons.cancel -text Cancel -command "destroy $w"
#button $w.buttons.refres -text Refresh -command "filelist $w.mask.e1 $w.frame.list" 
#button $w.buttons.list -text list -command "ilist $w.frame.list" 
#pack $w.buttons.ok $w.buttons.cancel -side left -expand 1
#pack $w.buttons.refres $w.buttons.list

frame $w.right.lf 
pack $w.right.lf -side top  
scrollbar $w.right.lf.scroll -command "$w.right.lf.list yview"
listbox $w.right.lf.list -width 15 -selectmode extended -yscroll "$w.right.lf.scroll set" -setgrid 1 -height 12
button $w.right.refres -text Refresh -command "filelist $w.right.mask.e1 $w.right.lf.list" 
pack $w.right.lf.scroll -side right -fill y 
pack $w.right.lf.list -side right 
pack $w.right.refres -side bottom -padx 10 -pady 10
#$w.right.lf.list 

bind $w.right.lf.list <Button-1> { curselection }

frame $w.right.mask
pack $w.right.mask -side bottom  -fill x -padx 10 -expand yes
scrollbar $w.right.mask.smask -orient horiz -command "$w.right.mask.e1 yview"
entry $w.right.mask.e1 -xscrollcommand "$w.right.mask.smask set" -width 15
label $w.right.mask.l1 -text "File mask to selection:"
pack $w.right.mask.l1 -side top 
pack $w.right.mask.smask $w.right.mask.e1 -side bottom -fill x 

$w.right.mask.e1 insert end "*.*" 

filelist $w.right.mask.e1 $w.right.lf.list

#foreach i [glob *] {
#foreach i [lsort [glob * .*]] {
#foreach i [glob [$w.mask.e1 get]] {
#  $w.frame.list insert end $i
#}

$w.right.lf.list selection set 1 1

#for {set i 0} {$i < [$w.frame.list size]} {incr i} {
#    if {[$w.frame.list selection includes $i ] == 1}  {
#    puts [$w.frame.list get $i]
#  }
#}

#ilist $w.right.lf.list

frame $w.left.w
pack $w.left.w -side top
text $w.left.w.t -width 60  -xscrollcommand "$w.left.w.s1 set" \
               -height 20 -yscrollcommand "$w.left.w.s2 set" \
               -wrap none 
scrollbar $w.left.w.s1 -orient horiz -command "$w.left.w.t xview"
scrollbar $w.left.w.s2 -command "$w.left.w.t yview"
pack $w.left.w.s1 -side bottom -fill x
pack $w.left.w.s2 -side right -fill y
pack $w.left.w.t -expand yes -fill both

frame $w.left.but
pack $w.left.but -side bottom

button $w.left.but.cancel -text Cancel -command "destroy $w"
button $w.left.but.convert -text Convert -default active \
	-command "$w.left.w.t insert end [selection get]"
#         -command "$w.left.w.t insert end jhgkd"
#        -command "puts [selection get]"


pack $w.left.but.convert  -pady 10 -padx 10 -side left 
pack $w.left.but.cancel -pady 10 -padx 10 -side right 

$w.left.w.t insert end "jksghfdfgdfgggggggggggggggggggggggggggkhskg\n"

